This is a replication folder for Kim, Londregan, and Ratkovic (2017). All data and scripts needed to generate the figures and results in the paper are present in this folder.

This file contains two components.  The first is a list and description 
of all objects in this folder.  The second, which starts at about line 
seventy, containst the instructions for actually carrying out the replication.

####################################
####################################
####################################
### I)  Overview
####################################
####################################
The folder contains four sets of files.  First are the data files.  Second is the R package for the primary analysis.  Third are the scripts for the secondary analyses.  Fourth are output files.

For a quick entry, sourcing SFA_Figures.R gives the figures in the paper.  Sourcing SFAReplication.R will do a long run of the votes and words model for the 112th Senate, but if you open the script you will see options for how to do either a short or long run, using all the different senates.

I) Data files
1)  criterion: R object with results from estimating the crtieria for selecting alpha, which balances the information coming from words and votes. 
2)  dtm*: R objects that contain legislator-term matrices, cleaned, indexed by Congress.
3)  dtmbig*: R objects that contain legislator-term matrices, not cleaned or trimmed, by Congress.
4)  dwnom*.csv: supplemental information on US Senators, indexed by Congress
5)  votemat*: roll call votes used in this analysis, indexed by Congress
6)  matrix112, missingmat112: files with formatted 112th Senate data.
7)  media.mat: term document matrix from WSJ, NYT, and Wash Post supplemental analysis

II) R files for the analysis
1) Prior to running the analysis, you should load the R package sfaPA by opening a console in the directory with the file "sfaPA_0.1.0.tar.gz" and, in the console, type “R CMD INSTALL sfaPA_0.1.0.tar.gz"
2) Source install_packages.R.  This will ensure all required packages are present.
3) Functions_Criteria.R contains functions for generating WAIC statistics for selecting the balance in information coming from words and votes 
4) Functions_Media.R contains functions for analyzing the WSJ, NYT, and Wash Post supplemental analysis

III) Analyses
1) Criterion_SFA.R: Generates the criterion estimates for balancing information between words and votes.
2) ImputeExerceise_leaders.R,  ImputeExerceise_random.R,  ImputeExerceise_replication.R: Script for supplemental analyses with only leaders having observed vote counts, random legislators given missing vote outcomes, and a full-data analysis for comparison.
3) ImputeNews.R: for supplemental analysis scaling WSJ, Wash Post, and NYT.
4) SFAReplication.R:  Replicates the primary analysis

IV) Output files
1) ImputeExercisesFit: Output from running imputation exercise (imputeexerciseleaders.R)
2) obj_both_*; obj_votes_*; obj_words_*: Results from SFA using both words and votes, votes only, and words only.
3) scale.media: results from scaling media supplemental analysis
4) sfavswordsfishrun: results from scaling words on 112th Senate; formatted for comparison w swordfish
5) criterion: results from looking for criterion
6) ImputeExercisesFit: contains results for cutting lines figure in main body

The following R packages were used in this analysis: 
1) msm version 1.6.4
2) MASS version 7.3-45
3) VGAM version 1.0-2
4) distr version 2.6
5) truncnorm version 1.0-7
6) Rcpp version 0.12.7
7) RcppArmadillo version 0.7.500.0.0
8) inline version 0.3.8
9) RcppEigen version 0.3.2.9.0 
10) rjson version 0.6-2
11) tm version 0.2.15
12) RWeka version 0.4-29
13) xtable version  1.8-2
14) devtools version  1.13.3
15) quanteda version 0.99 
Please note that these packages appear stable and should give identical results across different releases.

########################################################################
########################################################################
########################################################################
### II)  Instructions for Replication
########################################################################
########################################################################
########################################################################
Instructions for replication are below.

As these analyses are time-consuming, the examples below offer switches to turn on/off
short runs.  See individual files for details.  Please note that the scripts are set such that they will _not_ automatically save results, so as not to overwrite the included output.  To save output, see each script.

1) Install sfaPA_0.1.tar.gz and source install_packages.R.  This will ensure the required libraries and functions are in place.
2) Sourcing SFA_Figures.R will recreate the figures in the main body, using output files in this folder
3) Sourcing SFA_SupplementalFigures.R will recreate the figures and a table in the supplemental materials, using output files in this folder
4) Sourcing SFAReplication.R will replicates the primary analysis
5) Sourcing Criterion_SFA.R will generates the criterion estimates for balancing information between words and votes.
6) Sourcing ImputeExerceise_leaders.R,  ImputeExerceise_random.R,  ImputeExerceise_replication.R will conduct supplemental analyses with only leaders having observed vote counts, random legislators given missing vote outcomes, and a full-data analysis for comparison.
7) Sourcing ImputeNews.R will conduct supplemental analysis scaling WSJ, Wash Post, and NYT.

Additional Notes
*) “save.each” is an option in our workhorse function for saving intermediate results.  Please leave this set to FALSE.
#
